/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 *
 * @author thiago
 */
public class utilitarios {

    public String formatString(String string, String mask)
            throws java.text.ParseException {
        javax.swing.text.MaskFormatter mf =
                new javax.swing.text.MaskFormatter(mask);
        mf.setValueContainsLiteralCharacters(false);
        return mf.valueToString(string);
    }

    public String formatDinheiro(double value) {
        DecimalFormat df = new DecimalFormat("#,###.00");
        return "R$ " + df.format(value);
    }

    public String formatDinheiro(String value) {
        double d = Double.parseDouble(value);
        DecimalFormat df = new DecimalFormat("#,###.00");
        return "R$ " + df.format(d);
    }

    public java.sql.Date formatDate(java.util.Date data) {
        return new java.sql.Date(data.getTime());
    }

    public String converteData(java.util.Date dtData) {
        SimpleDateFormat formatBra;
        formatBra = new SimpleDateFormat("dd/MM/yyyy");
        try {
            return formatBra.format(dtData);
        } catch (Exception e) {
            return "aaa";
        }
    }

    public java.sql.Date getHoje() {
        Calendar c = Calendar.getInstance();
        return new java.sql.Date(c.getTimeInMillis());
    }
}
